﻿using PaperMaster.Chess.CardSpace;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PaperMaster.Chess.CardSpace
{
    ///这样的一个文件内最好包含Model，Controller和ViewController三个组件，但是文件名要
    ///叫XXXViewController以便添加给物体

    /// <summary>
    /// 这张卡片的数据模型，需要继承自CardModelBase，并实现ISingleCardModel<自己>接口
    /// </summary>
    public class SampleCardModel : CardModelBase,ISingleCardModel<SampleCardModel>
    {
        public int playCount;
        /// <summary>
        /// 默认的数据将从JSON文件读取，但新添加的数据需要初始化
        /// </summary>
        public SampleCardModel() : base(Card.Sample)
        {
            Init();
        }
        /// <summary>
        /// 通过指定一个默认模型的方式创建卡牌，这个函数也请提供
        /// </summary>
        /// <param name="m"></param>
        public SampleCardModel(AbstractCardModelBase m) : base(m)
        {
            Init();
        }
        /// <summary>
        /// 该函数只需添加新增加的成员即可
        /// </summary>
        protected override void Init()
        {
            playCount = 0;
        }
        /// <summary>
        /// 实现Copy接口，复制新添加的数据
        /// </summary>
        /// <param name="card"></param>
        public void Copy(SampleCardModel card)
        {
            this.playCount = card.playCount;
            base.Copy(card);
        }
    }
    public class SampleCardController : CardControllerBase
    {
        /// <summary>
        /// 将模型指定为自己的模型
        /// </summary>
        public SampleCardController() : base()
        {
            model = new SampleCardModel();

        }
        ///如果打算快捷地使用模型，可以这样
        SampleCardModel tModel
        {
            get
            {
                return (SampleCardModel)model;
            }
            set
            {
                model = value;
            }
        }

        /// <summary>
        /// 抽到该卡时触发该效果
        /// </summary>
        public override void DrawIn()
        {
            Debug.Log("我来也");
        }

        /// <summary>
        /// 打出该卡时触发的效果,注意一定要以return base.Play()结尾
        /// 若发现打出牌的条件不满足，就先调用PreConditionInfo，再返回false
        /// </summary>
        public override bool Play()
        {
            Debug.Log("鲨了你！" + tModel.playCount);
            if (ChessBoardController.GetController().SetPiece(PieceSpace.Piece.SamplePiece, PieceSpace.PieceOwner.Player))
            {
                tModel.playCount++;
            }
            else
            {
                PreConditionInfo();
                return false;
            }
            return base.Play();
        }

        /// <summary>
        /// 弃掉该卡时触发此效果
        /// </summary>
        public override void WashedAway()
        {
            Debug.Log("我去也");
        }

        public override CardModelBase CopyModel()
        {
            SampleCardModel nModel = new SampleCardModel();
            nModel.Copy((SampleCardModel)this.model);
            return nModel;
        }

    }
    /// <summary>
    /// 卡牌需要一个界面控制器
    /// </summary>
    public class SampleCardViewController : CardViewController
    {
        private void Awake()
        {
            Init();
        }
        /// <summary>
        /// 初始化函数，请重写，内部至少要完成controller的创建
        /// </summary>
        protected override void Init()
        {
            controller = new SampleCardController();
            base.Init();
        }
    }
}
